# -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import fields, osv
from openerp.tools.translate import _
import re
#----------------------------------------------------------
# Products
#----------------------------------------------------------

class product_template(osv.osv):
    _inherit = "product.template"

    _columns = {
        'type': fields.selection([('product','Stockable Product'),('service','Service')], 'Product Type', required=True, help="a service is a non-material product provided by a company or an individual. \nStockable product: Will imply stock management for this product."),
        'cost_method': fields.property(type='selection', selection=[('standard', 'Standard Price'), ('average', 'Average Price'), ('real', 'Real Price')],
                    help="""Standard Price: The cost price is manually updated at the end of a specific period (usually every year).
                            Average Price: The cost price is recomputed at each incoming shipment and used for the product valuation.
                            Real Price: The cost price displayed is the price of the last outgoing product (will be use in case of inventory loss for example).""",
                    string="Costing Method", required=True, copy=True),
    }

    _defaults = {
        'type' : 'product',
    }

#set at ir.property for default cost method and valuation

    def _check_name(self, cursor, user, ids, context=None):
        for product in self.browse(cursor, user, ids, context=context):
            if self.search(cursor, user, [('name','=', product.name),('id', '!=', product.id)]):
                return False


        return True
 
    _constraints = [
        (_check_name, 'Error: Product Name must be unique per Product Name!', ['name',]),
    ]


product_template()


# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
